package cn.melonlib.cores.graphql.config.bean.impl;

import cn.hutool.core.map.MapUtil;
import cn.melonlib.cores.graphql.config.bean.ParameterReader;
import cn.melonlib.cores.graphql.model.input.GraphQLOrderBy;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class OrderByReader implements ParameterReader<GraphQLOrderBy> {

    @Override
    public GraphQLOrderBy read(String fieldName, DataFetchingEnvironment env, Class<GraphQLOrderBy> cls) throws Exception {
        Map<String,String> map= env.getArgument(fieldName);
        if(MapUtil.isEmpty(map)){
            return null;
        }
        return new GraphQLOrderBy(map.get("field"),map.get("type"));
    }
}
